package kr.hkit.androidcomplete01.ch13;

import kr.hkit.androidcomplete01.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.EditText;

public class WebViewTest extends Activity {
	private WebView mWeb;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch13_webviewtest);
		
		mWeb = (WebView) findViewById(R.id.web);
		mWeb.setWebViewClient(new MyWebClicent());
		WebSettings set = mWeb.getSettings();
		set.setJavaScriptEnabled(true);
		set.setBuiltInZoomControls(true);
		mWeb.loadUrl("http://www.google.com");
	}
	
	public void mOnClick(View v){
		switch(v.getId()){
		case R.id.btngo:
			String url;
			EditText addr = (EditText) findViewById(R.id.address);
			url = addr.getText().toString();
			mWeb.loadUrl(url);
			break;
		case R.id.btnback:
			if(mWeb.canGoBack()){
				mWeb.goBack();
			}
			break;
		case R.id.btnforward:
			if(mWeb.canGoForward()){
				mWeb.goForward();
			}
			break;
		case R.id.btnlocal:
			mWeb.loadUrl("file://android_asset/test.html");
			break;
		}
	}
	
	class MyWebClicent extends WebViewClient{
		public boolean shouldOverrideUrlLoading(WebView view, String url){
			view.loadUrl(url);
			return true;
		}
	}
}
